using Newtonsoft.Json;
using System;
using System.Collections;

namespace Tyng.Web.UI.YUI
{
    public class ContextAlignment : Alignment
    {
        string _parentId;
        
        public ContextAlignment(string contextElementId, Corner childCorner, Corner parentCorner) : base(childCorner, parentCorner)
        {
            _parentId = contextElementId;
        }

        [JsonIgnore]
        public string ContextElementId { get { return _parentId; } }
    }

    public class ContextAlignmentJsonConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(ContextAlignment).IsAssignableFrom(objectType);
        }

        public override void WriteJson(JsonWriter writer, object value)
        {
            ContextAlignment typedValue = (ContextAlignment)value;

            writer.WriteStartArray();
            writer.WriteValue(typedValue.ContextElementId);
            writer.WriteValue(Alignment.GetCornerString(typedValue.ParentCorner));
            writer.WriteValue(Alignment.GetCornerString(typedValue.ChildCorner));
            writer.WriteEndArray();
        }

        public override object ReadJson(JsonReader reader, Type objectType)
        {
            throw new NotImplementedException();
        }
    }
}
